package com.elai.baseconfig.service.impl;

import com.alibaba.fastjson.JSON;
import com.elai.baseconfig.domain.*;
import com.elai.baseconfig.service.*;
import com.elai.common.core.redis.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.TimeUnit;


//存储系统公共Redis信息
@Service
public class BaseRedisServiceImpl implements BaseRedisService
{

    private int expireTime=999999999;
    //黑名单key
    private static String   BASEBLACKLIST_KEY="BASEBLACKLIST_KEY";
    //应用key
    private static String   BASEAPPLICATIONINFODOLIST_KEY="BASEAPPLICATIONINFODOLIST_KEY";
    //事件key
    private static String   EVENTTYPEDOLIST_KEY="EVENTTYPEDOLIST_KEY";
    //事件属性key
    private static String   EVENTITEMDOLIST_KEY="EVENTITEMDOLIST_KEY";
    //用户属性key
    private static String   BASEUSERATTRIBUTESDOLIST_KEY="BASEUSERATTRIBUTESDOLIST_KEY";

    @Autowired
    private RedisCache redisCache;
    @Autowired
    private BaseBlackListService baseBlackListService;
    @Autowired
    private BaseApplicationInfoService baseApplicationInfoService;
    @Autowired
    private EventItemService eventItemService;
    @Autowired
    private EventTypeService eventTypeService;
    @Autowired
    private BaseUserAttributesService  baseUserAttributesService;
    @Override
    public void saveBaseRedis() {
        //查询黑名单信息
        BaseBlackListDO baseBlackListDO=new BaseBlackListDO();
        baseBlackListDO.setStatus("Y");
        List<BaseBlackListDO> listDOList=  baseBlackListService.selectBaseBlackListList(baseBlackListDO);

        redisCache.setCacheObject(BASEBLACKLIST_KEY, JSON.toJSONString(listDOList), expireTime, TimeUnit.MINUTES);
        //查询应用
        BaseApplicationInfoDO baseApplicationInfoDO=new BaseApplicationInfoDO();
        baseApplicationInfoDO.setStatus("Y");
        List<BaseApplicationInfoDO> baseApplicationInfoDOList=baseApplicationInfoService.selectBaseApplicationInfoList(baseApplicationInfoDO);
        redisCache.setCacheObject(BASEAPPLICATIONINFODOLIST_KEY, JSON.toJSONString(baseApplicationInfoDOList), expireTime, TimeUnit.MINUTES);
        // 查询事件
        EventTypeDO eventTypeDO=new EventTypeDO();
        eventTypeDO.setStatus("N");
        List<EventTypeDO> eventTypeDOList=eventTypeService.selectEventTypeList(eventTypeDO);
        redisCache.setCacheObject(EVENTTYPEDOLIST_KEY, JSON.toJSONString(eventTypeDOList), expireTime, TimeUnit.MINUTES);
        // 查询事件属性
        EventItemDO eventItemDO=new EventItemDO();
        eventItemDO.setStatus("N");
        List<EventItemDO> eventItemDOList=eventItemService.selectEventItemList(eventItemDO);
        redisCache.setCacheObject(EVENTITEMDOLIST_KEY, JSON.toJSONString(eventItemDOList), expireTime, TimeUnit.MINUTES);
        //查询用户属性
        BaseUserAttributesDO baseUserAttributesDO =new BaseUserAttributesDO();
        //预设字段后续用于是否有效使用
        baseUserAttributesDO.setPreSetFlag("N");
        List<BaseUserAttributesDO> baseUserAttributesDOList=baseUserAttributesService.selectBaseUserAttributesList(baseUserAttributesDO);
        redisCache.setCacheObject(BASEUSERATTRIBUTESDOLIST_KEY, JSON.toJSONString(baseUserAttributesDOList), expireTime, TimeUnit.MINUTES);
    }


}
